package com.ruoyi.lxy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.ruoyi.common.core.service.OssService;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.lxy.domain.*;
import com.ruoyi.lxy.domain.bo.TQuestionnaireReslutBo;
import com.ruoyi.lxy.domain.vo.*;
import com.ruoyi.lxy.mapper.*;
import com.ruoyi.lxy.service.ITSelectUserService;
import com.ruoyi.lxy.service.ITTimeService;
import com.ruoyi.lxy.zust.domain.TStaff;
import com.ruoyi.lxy.zust.mapper.DepartmentMapper;
import com.ruoyi.lxy.zust.service.ITStaffService;
import com.ruoyi.lxy.zust.service.impl.TDepartmentServiceImpl;
import com.ruoyi.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import com.ruoyi.lxy.domain.bo.TRouteBo;
import com.ruoyi.lxy.domain.vo.TRouteVo;
import com.ruoyi.lxy.domain.TRoute;
import com.ruoyi.lxy.mapper.TRouteMapper;
import com.ruoyi.lxy.service.ITRouteService;

import java.math.BigDecimal;
import java.sql.Time;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 路线Service业务层处理
 *
 * @author ruoyi
 * @date 2023-08-24
 */
@RequiredArgsConstructor
@Service
public class TRouteServiceImpl implements ITRouteService {

    private final TRouteMapper baseMapper;
    private final TQuestionnaireReslutMapper tQuestionnaireReslutMapper;
    private final ISysOssService iSysOssService;
    private final OssService ossService;
    private final TProjectTravelagenMapper projectTravelagenMapper;
    private final TProjectMapper projectMapper;
    private final ITStaffService itStaffService;
    private final TUserMapper userMapper;
    private final TTimeMapper tTimeMapper;
    private final TSelectUserMapper selectUserMapper;
    final TDepartmentServiceImpl tdepartmentService;

    /**
     * 查询路线
     */
    @Override
    public TRouteVo queryById(Long id) {
        return StateTransitionVo(baseMapper.selectVoById(id));
    }

    /**
     * 管理员查询路线列表
     * 对于路线区域：0省内 1省外 3国外
     * 对于路线携带家属：0 允许 1 不允许
     * 对于是否为专属：0是 1否
     * 对于状态：0未提交（管理员看不到）1待审核
     * 2未通过,3已通过,
     * 4选为问卷（旅行社无法看到该状态）
     */
    @Override
    public TableDataInfo<TRouteVo> queryPageList(TRouteBo bo, PageQuery pageQuery) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(tRouteBo);
        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {
            tRouteVo.setPic(ossService.selectUrlByIds(tRouteVo.getPic()));
            transformedList.add(StateTransitionVo(tRouteVo));
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        // 返回 result 值
        return TableDataInfo.build(result);
    }

    @Override
    public TableDataInfo<TRouteVo> AdminqueryPageList(TRouteBo bo, PageQuery pageQuery) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(tRouteBo);
        //管理员查询列表时，排除未提交路线查看
        lqw.ge(TRoute::getStatusCode, 1);
        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {
            tRouteVo.setPic(ossService.selectUrlByIds(tRouteVo.getPic()));
            transformedList.add(StateTransitionVo(tRouteVo));
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        // 返回 result 值
        return TableDataInfo.build(result);
    }

    /**
     * 管理员查询路线列表-满意度查看
     */
    @Override
    public TableDataInfo<TRouteVo> AdminqueryPageListGrade(TRouteBo bo, PageQuery pageQuery) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(tRouteBo);
        //管理员查询列表时，排除未提交路线查看
        lqw.ge(TRoute::getStatusCode, 1);
        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {
            Long id = tRouteVo.getId();
            TRouteVo tRouteVo2 = satisfactionResult(id);
            if (tRouteVo2 != null) {
                tRouteVo.setSatisfactionResult(tRouteVo2.getSatisfactionResult());
            }
            transformedList.add(StateTransitionVo(tRouteVo));
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        // 返回 result 值
        return TableDataInfo.build(result);
    }

    /**
     * 用户查询路线列表
     */

    public TableDataInfo<TRouteVo> UserqueryPageList(TRouteBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(bo);
//如果起始时间和结束时间为空，设置起始时间和结束时间为无穷小和无穷大
        if (bo.getStartTime() == null) {
            bo.setStartTime("1999-01-01 00:00:00");
        }
        if (bo.getEndTime() == null) {
            bo.setEndTime("2050-01-01 00:00:00");
        }
        TStaff tStaff = itStaffService.selectByZgh(userMapper.selectById(LoginHelper.getLoginUser().getUserId()).getZgh());
        //用户查询列表时，添加时间段筛选

        lqw.inSql(TRoute::getId, "select route_id from t_time where start_time between '" + bo.getStartTime() + "' and '" + bo.getEndTime() + "' and end_time between '" + bo.getStartTime() + "' and '" + bo.getEndTime() + "'");
        //用户查询列表时，排除专属路线
        lqw.eq(TRoute::getAllowUnifiedCode, 1);
        //用户查询列表时，获取自己的专属部门路线

        lqw.or(qw -> qw.eq(TRoute::getAllowUnifiedCode, 0).eq(TRoute::getDepartmentNo, tStaff.getDWDM()));
        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {
            tRouteVo.setPic(ossService.selectUrlByIds(tRouteVo.getPic()));
            transformedList.add(StateTransitionVo(tRouteVo));
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        return TableDataInfo.build(result);
    }

    /**
     * 旅行社查询路线列表
     */
    public TableDataInfo<TRouteVo> TravelagenqueryPageList(TRouteBo bo, PageQuery pageQuery,boolean isBefore) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(tRouteBo);

        //询旅行社对应的项目ids
        LambdaQueryWrapper<TProject> lqw1 = Wrappers.lambdaQuery();
        lqw1.eq(TProject::getStatusCode, 0).or().eq(TProject::getStatusCode, 1);
        List<TProjectVo> tProjects = projectMapper.selectVoList(lqw1);
        if(isBefore){
            lqw.ne(TRoute::getProjectId,tProjects.get(0).getId());
        }else{
            lqw.eq(TRoute::getProjectId,tProjects.get(0).getId());
        }
        //属于旅行社的路线
        lqw.eq(TRoute::getTravelagenId,LoginHelper.getLoginUser().getUserId());

        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {

            tRouteVo.setPic(ossService.selectUrlByIds(tRouteVo.getPic()));
            TRouteVo tRouteVo1 = StateTransitionVo(tRouteVo);
            if (tRouteVo1.getStatusCode() == 4) tRouteVo1.setStatus("待审核");
            transformedList.add(tRouteVo1);
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        // 返回 result 值
        return TableDataInfo.build(result);
    }
    /**
     * 旅行社查询过往路线列表
     */
    @Override
    public TableDataInfo<TRouteVo> TravelagenqueryPageListformerly(TRouteBo bo, PageQuery pageQuery) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(tRouteBo);
        //询旅行社当前项目id
        LambdaQueryWrapper<TProject> lqw1 = Wrappers.lambdaQuery();
        lqw1.eq(TProject::getStatusCode, 0).or().eq(TProject::getStatusCode, 1);
        List<TProjectVo> tProjects = projectMapper.selectVoList(lqw1);
        //排除路线项目id为当前项目id的路线
        lqw.ne(TRoute::getProjectId,tProjects.get(0).getId());
        lqw.eq(TRoute::getTravelagenId,LoginHelper.getLoginUser().getUserId());



        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        List<TRouteVo> transformedList = new ArrayList<>();
        for (TRouteVo tRouteVo : result.getRecords()) {

            tRouteVo.setPic(ossService.selectUrlByIds(tRouteVo.getPic()));
            TRouteVo tRouteVo1 = StateTransitionVo(tRouteVo);
            if (tRouteVo1.getStatusCode() == 4) tRouteVo1.setStatus("待审核");
            transformedList.add(tRouteVo1);
        }
        // 将转换后的结果设置回 Page 对象
        result.setRecords(transformedList);
        // 返回 result 值
        return TableDataInfo.build(result);
    }
    /**
     * 查询路线列表
     */
    @Override
    public List<TRouteVo> queryList(TRouteBo bo) {
        LambdaQueryWrapper<TRoute> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<TRoute> buildQueryWrapper(TRouteBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<TRoute> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, TRoute::getId, bo.getId());
        lqw.eq(bo.getProjectId() != null, TRoute::getProjectId, bo.getProjectId());
        lqw.like(StringUtils.isNotBlank(bo.getName()), TRoute::getName, bo.getName());
        lqw.eq(bo.getAreaCode() != null, TRoute::getAreaCode, bo.getAreaCode());
        lqw.eq(bo.getCanBringCode() != null, TRoute::getCanBringCode, bo.getCanBringCode());
        lqw.eq(bo.getAllowUnifiedCode() != null, TRoute::getAllowUnifiedCode, bo.getAllowUnifiedCode());
        lqw.eq(bo.getStatusCode() != null, TRoute::getStatusCode, bo.getStatusCode());
        lqw.eq(bo.getQuestionnaireId() != null, TRoute::getQuestionnaireId, bo.getQuestionnaireId());
        return lqw;
    }

    /**
     * 管理员新增路线
     */
    @Override
    public Boolean insertByBo(TRouteBo bo) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        tRouteBo.setStatusCode(3);
        TRoute add = BeanUtil.toBean(tRouteBo, TRoute.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            tRouteBo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 旅行社新增路线
     */
    @Override
    public Boolean TravelagenqueryinsertByBo(TRouteBo bo) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        tRouteBo.setStatusCode(0);
        LambdaQueryWrapper<TProject> lqw = Wrappers.lambdaQuery();
        lqw.eq(TProject::getStatusCode, 0).or().eq(TProject::getStatusCode, 1);
        tRouteBo.setProjectId(projectMapper.selectVoList(lqw).get(0).getId());
        tRouteBo.setTravelagenId(LoginHelper.getLoginUser().getUserId());
        TRoute add = BeanUtil.toBean(tRouteBo, TRoute.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            tRouteBo.setId(add.getId());
        }
        return flag;
    }

    @Override
    public Boolean TravelagenAddBeforeRoute(Long[] ids) {
        for(Long id:ids){
            TRouteVo vo=queryById(id);
            TRouteBo bo=new TRouteBo();
            BeanUtil.copyProperties(vo,bo);
            bo.setId(null);
            bo.setCanBring(null);
            bo.setAllowUnified(null);
            bo.setDepartmentNo(null);
            bo.setQuestionnaireId(null);
            bo.setVotes(0);
            bo.setNoPassReason(null);
            System.out.println(bo);
            TravelagenqueryinsertByBo(bo);
        }
        return true;
    }

    /**
     * 管理员修改路线
     */
    @Override
    public Boolean updateByBo(TRouteBo bo) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        TRoute update = BeanUtil.toBean(tRouteBo, TRoute.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 旅行社修改路线
     */
    @Override
    public Boolean TravelagenqueryupdateByBo(TRouteBo bo) {
        //只能修改status为0或4的路线
        if (bo.getStatusCode() != 0 && bo.getStatusCode() != 2) {
            return false;
        }
        TRouteBo tRouteBo = StateTransitionBo(bo);
        TRoute update = BeanUtil.toBean(tRouteBo, TRoute.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }
    /**
     * 旅行社提交过往路线
     */
    @Override
    public Boolean TravelagenquerysubmitByBo(TRouteBo bo) {
        TRouteBo tRouteBo = StateTransitionBo(bo);
        //设置状态为待审核
        tRouteBo.setStatusCode(0);
        LambdaQueryWrapper<TProject> lqw = Wrappers.lambdaQuery();
        lqw.eq(TProject::getStatusCode, 0).or().eq(TProject::getStatusCode, 1);
        tRouteBo.setProjectId(projectMapper.selectVoList(lqw).get(0).getId());
        //投票数归零
        tRouteBo.setVotes(0);
        //设置专属部门为空
        tRouteBo.setDepartmentNo(null);
        //设置专属部门路线为否
        tRouteBo.setAllowUnifiedCode(1);
        //设置问卷id为空
        tRouteBo.setQuestionnaireId(null);
        TRoute add = BeanUtil.toBean(tRouteBo, TRoute.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            tRouteBo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(TRoute entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 管理员批量删除路线
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }

        //根据id搜索公告
        List<TRouteVo> vos = getPicIds(ids, true);

        //查询公告的ossIds并删除文件
        for (int i = 0; i < vos.size(); i++) {
            String oss = vos.get(i).getPic();

            //根据逗号分割不同的ossId
            if (oss != null) {
                String[] ossIds = oss.split(",");
                for (String s : ossIds) {
                    iSysOssService.deleteWithValidByIds(Arrays.asList(Long.valueOf(s)), true);
                }
            }
        }


        return baseMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public Boolean submitWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
            //只有status为0的路线才能提交
            for (Long id : ids) {
                // Retrieve the TRouteVo object for the current id
                TRouteVo routeVo = queryById(id);

                // Check the status field of the TRouteVo object
                if (routeVo != null && routeVo.getStatusCode() != 0 && routeVo.getStatusCode() != 4) {
                    // If status is not 0 or 4, return false
                    return false;
                }
            }
        }
        UpdateWrapper<TRoute> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        TRoute updateEntity = new TRoute();
        updateEntity.setStatusCode(1); // 设置 status 字段为 1
        return baseMapper.update(updateEntity, updateWrapper) > 0;

    }

    /**
     * 旅行社删除路线
     */
    @Override
    public Boolean TravelagenquerydeleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
            for (Long id : ids) {
                // Retrieve the TRouteVo object for the current id
                TRouteVo routeVo = queryById(id);

                // Check the status field of the TRouteVo object
                if (routeVo != null && routeVo.getStatusCode() != 0) {
                    // If status is not 0, return false
                    return false;
                }
            }
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    public TRouteBo StateTransitionBo(TRouteBo tRouteBo) {
        if (tRouteBo.getArea() != null)
            switch (tRouteBo.getArea()) {
                case "省内":
                    tRouteBo.setAreaCode(0);
                    break;
                case "省外":
                    tRouteBo.setAreaCode(1);
                    break;
                case "国外":
                    tRouteBo.setAreaCode(2);
                    break;
            }
        if (tRouteBo.getCanBring() != null)
            switch (tRouteBo.getCanBring()) {
                case "允许":
                    tRouteBo.setCanBringCode(0);
                    break;
                case "不允许":
                    tRouteBo.setCanBringCode(1);
                    break;
            }
        if (tRouteBo.getAllowUnified() != null)
            switch (tRouteBo.getAllowUnified()) {
                case "是":
                    tRouteBo.setAllowUnifiedCode(0);
                    break;
                case "否":
                    tRouteBo.setAllowUnifiedCode(1);
                    break;
            }
        if (tRouteBo.getStatus() != null)
            switch (tRouteBo.getStatus()) {
                case "未提交":
                    tRouteBo.setStatusCode(0);
                    break;
                case "待审核":
                    tRouteBo.setStatusCode(1);
                    break;
                case "未通过":
                    tRouteBo.setStatusCode(2);
                    break;
                case "已通过":
                    tRouteBo.setStatusCode(3);
                    break;
                case "选为问卷":
                    tRouteBo.setStatusCode(4);
                    break;
            }

        return tRouteBo;
    }

    public TRouteVo StateTransitionVo(TRouteVo tRouteVo) {
        //专属部门代码转化为名称
        if(tRouteVo.getDepartmentNo()!=null && tRouteVo.getAllowUnifiedCode() != null && tRouteVo.getAllowUnifiedCode()==0){
            String[] departmentno=tRouteVo.getDepartmentNo().split(",");
            String DWMC="";
            for (String d:departmentno){
                DWMC+=(tdepartmentService.getDWMC(d));
                DWMC+="\n";
            }
            tRouteVo.setDepartmentNoCode(DWMC);
        }


        if (tRouteVo.getAreaCode() != null)
            switch (tRouteVo.getAreaCode()) {
                case 0:
                    tRouteVo.setArea("省内");
                    break;
                case 1:
                    tRouteVo.setArea("省外");
                    break;
                case 2:
                    tRouteVo.setArea("国外");
                    break;
            }
        if (tRouteVo.getCanBringCode() != null)
            switch (tRouteVo.getCanBringCode()) {


                case 0:
                    tRouteVo.setCanBring("允许");
                    break;
                case 1:
                    tRouteVo.setCanBring("不允许");
                    break;
            }
        if (tRouteVo.getAllowUnifiedCode() != null)
            switch (tRouteVo.getAllowUnifiedCode()) {
                case 0:
                    tRouteVo.setAllowUnified("是");
                    break;
                case 1:
                    tRouteVo.setAllowUnified("否");
                    break;
            }
        if (tRouteVo.getStatusCode() != null)
            switch (tRouteVo.getStatusCode()) {
                case 0:
                    tRouteVo.setStatus("未提交");
                    break;
                case 1:
                    tRouteVo.setStatus("待审核");
                    break;
                case 2:
                    tRouteVo.setStatus("未通过");
                    break;
                case 3:
                    tRouteVo.setStatus("已通过");
                    break;
                case 4:
                    tRouteVo.setStatus("选为问卷");
                    break;
            }
        return tRouteVo;
    }


    public List<TRouteVo> getPicIds(Collection<Long> ids, Boolean isValid) {
        return baseMapper.selectVoBatchIds(ids);
    }

    @Override
    public Boolean CheckRouteExist(Long projectId) {
        return baseMapper.exists(new LambdaQueryWrapper<TRoute>().eq(TRoute::getProjectId, projectId));
    }

    @Override
    public TableDataInfo<TRouteVo> voteQueryPageList(TRouteBo bo, PageQuery pageQuery) {
        TQuestionnaireReslutBo tQuestionnaireReslutBo;

        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<TRoute> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getQuestionnaireId() != null, TRoute::getQuestionnaireId, bo.getQuestionnaireId());
        Page<TRouteVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);


        return TableDataInfo.build(result);
    }

    //计算路线满意度
    public TRouteVo satisfactionResult(Long routeId){
        LambdaQueryWrapper<TSelectUser> lqw1 = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<TTime> lqw2 = new LambdaQueryWrapper<>();
        lqw2.eq(TTime::getCanGo,1);
        List<String> comments = new ArrayList<>();
        Float[] satisfactions = {0f, 0f, 0f, 0f, 0f};
        int selectUserNum = 0;
        //判断时间段是否存在
        if (tTimeMapper.exists(lqw2.eq(TTime::getRouteId, routeId))) {
            //获取路线的所有时间段id
            List<Long> timeIds = tTimeMapper.selectVoList(lqw2).stream()
                .map(TTimeVo::getId).collect(Collectors.toList());
            //获取所有时间段的所有用户选择
            for (Long timeId : timeIds) {
                lqw1.eq(TSelectUser::getTimeId, timeId);
                List<TSelectUserVo> tSelectUserVos = selectUserMapper.selectVoList(lqw1);
                if (tSelectUserVos.isEmpty())
                    continue;
                //获取所有用户的满意度和意见和建议
                for (TSelectUserVo tSelectUserVo : tSelectUserVos) {
                    if (!tSelectUserVo.getComment().isEmpty()) {
                        comments.add(tSelectUserVo.getComment());
                    }
                    if (!tSelectUserVo.getSatisfaction().isEmpty()) {
                        String[] satisfaction = tSelectUserVo.getSatisfaction()
                            .replaceAll("[\\[\\] ]", "")
                            .split(",");
                        //统计满意度，计算平均分
                        selectUserNum++;
                        for (int i = 0; i < satisfactions.length; i++) {
                            satisfactions[i] += Float.parseFloat(satisfaction[i]);
                        }
                    }
                }
            }
            //计算平均分
            for (int i = 0; i < satisfactions.length; i++) {
                satisfactions[i] = satisfactions[i] / selectUserNum;
            }
            TRouteVo tRouteVo = new TRouteVo();
            tRouteVo.setComments(comments);
            tRouteVo.setSatisfactionResult(satisfactions);
            return tRouteVo;
        } else {
            return null;
        }
    }

}
